package com.heatup.apt.management.service.impl;

import java.io.File;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.heatup.apt.common.constants.ResourceContants.ResourceResTypeEnum;
import com.heatup.apt.common.dao.OperativeMapper;
import com.heatup.apt.common.dao.ResourceMapper;
import com.heatup.apt.common.dao.coach.CoachInfoMapper;
import com.heatup.apt.common.util.DateUtils;
import com.heatup.apt.common.util.OssFileUtil;
import com.heatup.apt.common.util.StringUtil;
import com.heatup.apt.management.service.OperativeService;
import com.heatup.apt.model.coach.CoachInfo;
import com.heatup.apt.model.management.Article;
import com.heatup.apt.model.management.Articlescrap;
import com.heatup.apt.model.management.CoachInf;
import com.heatup.apt.model.management.CourseBanner;
import com.heatup.apt.model.management.HomeFigure;
import com.heatup.apt.model.management.InStore;
import com.heatup.apt.model.management.JsRSVideoInfo;
import com.heatup.apt.model.management.LemonShop;
import com.heatup.apt.model.management.LemonshopBanner;
import com.heatup.apt.model.management.SysUser;
import com.heatup.apt.model.management.VideoInfo;
import com.heatup.apt.model.management.VipActivity;
import com.heatup.apt.model.management.VipFigure;

@Service
public class OperativeServiceImpl implements OperativeService {

    @Resource
    private OperativeMapper operativeMapper;
    @Resource
    private ResourceMapper resourceMapper;
    @Resource
    private CoachInfoMapper coachInfoMapper;

    @Override
    public Map<Object, Object> queryHomeFirure() {
        Map<Object, Object> map = new HashMap<Object, Object>();
        List<HomeFigure> homeFigures = operativeMapper.queryHomeFigureList();
        map.put("homeFigures", homeFigures);
        return map;
    }

    @Override
	public Map<Object, Object> queryInStoreList() {
    	Map<Object, Object> map = new HashMap<Object, Object>();
        List<InStore> instore_list = operativeMapper.queryInStoreList();
        map.put("instore_list", instore_list);
		return map;
	}

    /**
     * 文章列表
     * <P>Author : fangxiaowen </P>      
     * <P>Date : 2016年10月18日 </P>
     * @return
     * @see com.heatup.apt.management.service.OperativeService#queryArticlescrapList()
     */
	@Override
    public Map<Object, Object> queryArticlescrapList() {
        Map<Object, Object> map = new HashMap<Object, Object>();
        List<Articlescrap> articlescrap_list = operativeMapper.queryArticlescrapList();
        map.put("articlescrap_list", articlescrap_list);
        return map;
    }

    @Override	
    public Map<Object, Object> querylemonshopBanner() {
        Map<Object, Object> map = new HashMap<Object, Object>();
        List<LemonshopBanner> lemonshopBanner = operativeMapper.querylemonshopBannerList();
        map.put("lemonshop_banner", lemonshopBanner);
        return map;
    }

    
    /**
     * 最受欢迎的课程
     * <P>Author : fangxiaowen </P>      
     * <P>Date : 2016年10月13日 </P>
     * @return
     * @see com.heatup.apt.management.service.OperativeService#queryCourseBanner()
     */
    @Override
    public Map<Object, Object> queryCourseBanner() {
        Map<Object, Object> map = new HashMap<Object, Object>();
        List<CourseBanner> courseBanner = operativeMapper.queryCourseBannerList();
        map.put("course_banner", courseBanner);
        return map;
    }

    @Override
    public int deleteFirure(Integer id) {
        return operativeMapper.deleteResourceById(id);
    }

    
    @Override
	public int deleteArticle(Integer id) {
		return operativeMapper.deleteArticleById(id);
	}

	@Override
    public int deleteVideo(Integer id) {
        return operativeMapper.deleteResourceById(id);
    }

    @Override
    public int addHomeFigure(MultipartFile multipartFile,HttpServletRequest request,String title,String previewUrl,SysUser user) throws Exception{
        com.heatup.apt.model.Resource resource = new com.heatup.apt.model.Resource();
        String path = request.getSession().getServletContext().getRealPath("img/homeFigure/");
        String fileName = multipartFile.getOriginalFilename();
        System.out.println(path);
        File targetFile = new File(path, fileName);
        if(!targetFile.exists()){
            targetFile.mkdirs();
        }
        multipartFile.transferTo(targetFile);
        String actionUrl = OssFileUtil.uploadFile(path +"/"+ fileName, fileName);
        resource.setResType(ResourceResTypeEnum.image.getType());
        resource.setResKey("homepage_banner");
        resource.setParentType("1");
        resource.setTitle(title);
        resource.setUrl(actionUrl);
        resource.setLink(previewUrl);
        resource.setCreatedBy(user.getId());
        resource.setCreatedTime(new Date());
        int count = resourceMapper.insertSelective(resource);
        resource.setSortNum(resource.getId());
        resourceMapper.updateByPrimaryKey(resource);
        return count;
    }
    
    
    @Override
	public int addZshykc(MultipartFile multipartFile,HttpServletRequest request, String title, String previewUrl,
			SysUser user) throws Exception {
        com.heatup.apt.model.Resource resource = new com.heatup.apt.model.Resource();
        String path = request.getSession().getServletContext().getRealPath("img/zshykc/");
        String fileName = multipartFile.getOriginalFilename();
        File targetFile = new File(path, fileName);
        if(!targetFile.exists()){
            targetFile.mkdirs();
        }
        multipartFile.transferTo(targetFile);
        String actionUrl = OssFileUtil.uploadFile(path +"/"+ fileName, fileName);
        resource.setResType(ResourceResTypeEnum.image.getType());
        resource.setResKey("course_banner");
        resource.setParentType("1");
        resource.setTitle(title);
        resource.setUrl(actionUrl);
        resource.setLink(previewUrl);
        resource.setCreatedBy(user.getId());
        resource.setCreatedTime(new Date());
        
        int count = resourceMapper.insertSelective(resource);
        
        resource.setSortNum(resource.getId());
        resourceMapper.updateByPrimaryKey(resource);
        return count;
	}

	/**
     * 添加文章
	 * OperativeService.addArticle()<BR>
	 * <P>Author :  fangxiaowen </P>  
	 * <P>Date : 2016年10月14日 </P>
	 * @param multipartFile 图片流
	 * @param request
	 * @param title 标题
	 * @param remark 备注
	 * @param link 文章链接
	 * @param coachId 教练ID
	 * @param user 当前用户
     * @return
     * @throws Exception
     * @see com.heatup.apt.management.service.OperativeService#addArticle(org.springframework.web.multipart.MultipartFile, javax.servlet.http.HttpServletRequest, java.lang.String, java.lang.String, java.lang.String, SysUser)
     */
    @Override
	public int addArticle(MultipartFile multipartFile,
			HttpServletRequest request, String title, String remark,String link,
			String coachId, SysUser user) throws Exception {
    	
    	Article article = new Article();
    	article.setRemark(remark);
    	article.setAuthor_id(Integer.valueOf(coachId));
    	article.setCreated_by(user.getId());
    	article.setTitle(title);
    	String path = request.getSession().getServletContext().getRealPath("img/article/");
        String fileName = multipartFile.getOriginalFilename();
        System.out.println(path);
        File targetFile = new File(path, fileName);
        if(!targetFile.exists()){
            targetFile.mkdirs();
        }
        multipartFile.transferTo(targetFile);
        String actionUrl = OssFileUtil.uploadFile(path +"/"+ fileName, fileName);
        
        article.setUrl(actionUrl);
        article.setLink(link);
        CoachInfo coachInfo = coachInfoMapper.selectById(Integer.valueOf(coachId));
        if (null != coachInfo) {
        	article.setAuthor_name(coachInfo.getNickName());
		}
        int count = operativeMapper.insertAcricle(article);
        
        Map<Object, Object> params = new HashMap<Object, Object>();
		params.put("sortNum", article.getId());
		params.put("id", article.getId());
		operativeMapper.updateSortArticle(params);
		
		return count;
	}
    
    
    /**
     * 修改文章
     * <P>Author : fangxiaowen </P>      
     * <P>Date : 2016年10月18日 </P>
     * @param multipartFile
     * @param request
     * @param title 文章标题
     * @param remark 文章摘要
     * @param link 文章链接
     * @param coachId 教练ID
     * @param id 文章ID
     * @param user 当前用户
     * @return
     * @throws Exception
     * @see com.heatup.apt.management.service.OperativeService#updateArticle(org.springframework.web.multipart.MultipartFile, javax.servlet.http.HttpServletRequest, java.lang.String, java.lang.String, java.lang.String, java.lang.Integer, SysUser)
     */
	@Override
	public int updateArticle(MultipartFile multipartFile,
			HttpServletRequest request, String title, String remark,String link,
			String coachId, Integer id, SysUser user) throws Exception {
		
        Map<Object, Object> params = new HashMap<Object, Object>();
        params.put("id", id);
        params.put("title", title);
        params.put("remark", remark);
        params.put("link", link);
        params.put("author_id", coachId);
        params.put("updatedBy", user.getId());
        CoachInfo coachInfo = coachInfoMapper.selectById(Integer.valueOf(coachId));
        if (null != coachInfo) {
        	params.put("author_name", coachInfo.getNickName());
		}
        if (null != multipartFile && multipartFile.getSize() > 0L)
        {
            String path = request.getSession().getServletContext().getRealPath("img/article/");
            String fileName = multipartFile.getOriginalFilename();
            System.out.println(path);
            File targetFile = new File(path, fileName);
            if(!targetFile.exists()){
                targetFile.mkdirs();
            }
            multipartFile.transferTo(targetFile);
            String actionUrl = OssFileUtil.uploadFile(path +"/"+ fileName, fileName);
            if (StringUtil.isNotEmpty(actionUrl)) {
                params.put("actionUrl", actionUrl);
            }
        }
        return operativeMapper.updateArticle(params);
	}

	/**
	 * 根据ID查询文章信息
	 * <P>Author : fangxiaowen </P>      
	 * <P>Date : 2016年10月18日 </P>
	 * @param id
	 * @return
	 * @see com.heatup.apt.management.service.OperativeService#queryArticleById(java.lang.Integer)
	 */
	@Override
	public Article queryArticleById(Integer id) {
		return operativeMapper.queryArticleById(id);
	}

	@Override
	public int addLemonbanner(MultipartFile multipartFile,
			HttpServletRequest request, String title, String previewUrl,
			SysUser user) throws Exception {
    	 com.heatup.apt.model.Resource resource = new com.heatup.apt.model.Resource();
         String path = request.getSession().getServletContext().getRealPath("img/lemon/");
         String fileName = multipartFile.getOriginalFilename();
         System.out.println(path);
         File targetFile = new File(path, fileName);
         if(!targetFile.exists()){
             targetFile.mkdirs();
         }
         multipartFile.transferTo(targetFile);
         String actionUrl = OssFileUtil.uploadFile(path +"/"+ fileName, fileName);
         resource.setResType(ResourceResTypeEnum.image.getType());
         resource.setResKey("lemonshop_banner");
         resource.setParentType("1");
         resource.setTitle(title);
         resource.setUrl(actionUrl);
         resource.setLink(previewUrl);
         resource.setCreatedBy(user.getId());
         resource.setCreatedTime(new Date());
         
         int count = resourceMapper.insertSelective(resource);
         
         resource.setSortNum(resource.getId());
         resourceMapper.updateByPrimaryKey(resource);
         return count;
	}
	

	@Override
	public int addInstore(MultipartFile multipartFile,
			HttpServletRequest request, String title, String previewUrl,
			SysUser user) throws Exception {
		com.heatup.apt.model.Resource resource = new com.heatup.apt.model.Resource();
        String path = request.getSession().getServletContext().getRealPath("img/instore/");
        String fileName = multipartFile.getOriginalFilename();
        System.out.println(path);
        File targetFile = new File(path, fileName);
        if(!targetFile.exists()){
            targetFile.mkdirs();
        }
        multipartFile.transferTo(targetFile);
        String actionUrl = OssFileUtil.uploadFile(path +"/"+ fileName, fileName);
        resource.setResType(ResourceResTypeEnum.image.getType());
        resource.setResKey("instore_banner");
        resource.setParentType("1");
        resource.setTitle(title);
        resource.setUrl(actionUrl);
        resource.setLink(previewUrl);
        resource.setCreatedBy(user.getId());
        resource.setCreatedTime(new Date());
        int count = resourceMapper.insertSelective(resource);
        
        resource.setSortNum(resource.getId());
        resourceMapper.updateByPrimaryKey(resource);
        return count;
	}

	@Override
	public int addOperatingVideo(MultipartFile multipartFile,
			HttpServletRequest request, String title, String previewUrl,
			String tags, String coachId, String duration,String videoClass, String res_key,SysUser user)
			throws Exception {
    	
    	com.heatup.apt.model.Resource resource = new com.heatup.apt.model.Resource();
        String path = request.getSession().getServletContext().getRealPath("video/");
        String fileName = multipartFile.getOriginalFilename();
        File targetFile = new File(path, fileName);
        if(!targetFile.exists())
        {
            targetFile.mkdirs();
        }
        multipartFile.transferTo(targetFile);
        String actionUrl = OssFileUtil.uploadFile(path +"/"+ fileName, fileName);
        resource.setResType(ResourceResTypeEnum.video.getType());
        resource.setLable(tags);
        resource.setDuration(duration);
        resource.setResKey(res_key);
        resource.setParentType("3");
        resource.setParentId(Integer.valueOf(coachId));
        resource.setVideoClass(videoClass);
        resource.setTitle(title);
        resource.setUrl(actionUrl);
        resource.setLink(previewUrl);
        resource.setCreatedBy(user.getId());
        resource.setCreatedTime(new Date());
        int count = resourceMapper.insertSelective(resource);
        
        resource.setSortNum(resource.getId());
        resourceMapper.updateByPrimaryKey(resource);
        
        return count;
	}

	@Override
    public int updateHomeFigure(MultipartFile multipartFile,
                                HttpServletRequest request, String title, String previewUrl,Integer id,
                                SysUser user) throws Exception {

        Map<Object, Object> params = new HashMap<Object, Object>();
        params.put("id", id);
        params.put("title", title);
        params.put("previewUrl", previewUrl);
        if (null != multipartFile && multipartFile.getSize() > 0L)
        {
            String current_date = DateUtils.format(new Date(), DateUtils.datePatternAllSimple);
            String path = request.getSession().getServletContext().getRealPath("img/homeFigure/");
            String fileName = current_date+"_"+multipartFile.getOriginalFilename();
            System.out.println(path);
            File targetFile = new File(path, fileName);
            if(!targetFile.exists()){
                targetFile.mkdirs();
            }
            multipartFile.transferTo(targetFile);
            String actionUrl = OssFileUtil.uploadFile(path +"/"+ fileName, fileName);
            if (StringUtil.isNotEmpty(actionUrl)) {
                params.put("actionUrl", actionUrl);
            }
        }
        return operativeMapper.updateHomeFigure(params);
    }
	
    @Override
	public int updateOperatingVideo(MultipartFile multipartFile,
			HttpServletRequest request, String title, String previewUrl,
			String tags, String coachId, String duration, String videoClass,
			Integer id, SysUser user) throws Exception {
    	
    	 Map<Object, Object> params = new HashMap<Object, Object>();
         params.put("id", id);
         params.put("title", title);
         params.put("previewUrl", previewUrl);
         params.put("tags", tags);
         params.put("coachId", coachId);
         params.put("videoClass", videoClass);
         params.put("duration", duration);
         if (null != multipartFile && multipartFile.getSize() > 0L){
             String current_date = DateUtils.format(new Date(), DateUtils.datePatternAllSimple);
             String path = request.getSession().getServletContext().getRealPath("img/homeFigure/");
             String fileName = current_date+"_"+multipartFile.getOriginalFilename();
             System.out.println(path);
             File targetFile = new File(path, fileName);
             if(!targetFile.exists()){
                 targetFile.mkdirs();
             }
             multipartFile.transferTo(targetFile);
             String actionUrl = OssFileUtil.uploadFile(path +"/"+ fileName, fileName);
             if (StringUtil.isNotEmpty(actionUrl)) {
                 params.put("actionUrl", actionUrl);
             }
         }
		return operativeMapper.updateVideoInf(params);
	}

    /**
     * 视频列表页
     * <P>Author : fangxiaowen </P>      
     * <P>Date : 2016年10月14日 </P>
     * @return
     * @see com.heatup.apt.management.service.OperativeService#queryVideoList()
     */
	@Override
    public Map<Object, Object> queryVideoList() {
        Map<Object, Object> map = new HashMap<Object, Object>();
        List<VideoInfo> video_list = operativeMapper.queryVideoList();
        map.put("video_list", video_list);
        return map;
    }
	
    @Override
	public Map<Object, Object> queryJsrfVideoList() {
    	Map<Object, Object> map = new HashMap<Object, Object>();
        List<JsRSVideoInfo> jsrsvideo_list = operativeMapper.queryJsrfVideoList();
        map.put("jsrsvideo_list", jsrsvideo_list);
        return map;
	}
    
    @Override
    public Map<Object, Object> querySfsxVideoList() {
    	Map<Object, Object> map = new HashMap<Object, Object>();
    	List<JsRSVideoInfo> sfsxvideo_list = operativeMapper.querySfsxVideoList();
    	map.put("sfsxvideo_list", sfsxvideo_list);
    	return map;
    }

    
    /**
     * 我要跑步视频列表
     * <P>Author : fangxiaowen </P>      
     * <P>Date : 2016年10月14日 </P>
     * @return
     * @see com.heatup.apt.management.service.OperativeService#queryWypbVideoList()
     */
	@Override
	public Map<Object, Object> queryWypbVideoList() {
		Map<Object, Object> map = new HashMap<Object, Object>();
    	List<JsRSVideoInfo> wypbvideo_list = operativeMapper.queryWypbVideoList();
    	map.put("wypbvideo_list", wypbvideo_list);
    	return map;
	}
	

	/**
	 * 我要蜜桃臂
	 * <P>Author : fangxiaowen </P>      
	 * <P>Date : 2016年10月17日 </P>
	 * @return
	 * @see com.heatup.apt.management.service.OperativeService#queryWymtbVideoList()
	 */
	@Override
	public Map<Object, Object> queryWymtbVideoList() {
		Map<Object, Object> map = new HashMap<Object, Object>();
    	List<JsRSVideoInfo> wymtbvideo_list = operativeMapper.queryWymtbVideoList();
    	map.put("wymtbvideo_list", wymtbvideo_list);
    	return map;
	}
	
	/**
	 * 我要马甲线
	 * <P>Author : fangxiaowen </P>      
	 * <P>Date : 2016年10月17日 </P>
	 * @return
	 * @see com.heatup.apt.management.service.OperativeService#queryWymjxVideoList()
	 */
	@Override
	public Map<Object, Object> queryWymjxVideoList() {
		Map<Object, Object> map = new HashMap<Object, Object>();
    	List<JsRSVideoInfo> wymjxvideo_list = operativeMapper.queryWymjxVideoList();
    	map.put("wymjxvideo_list", wymjxvideo_list);
    	return map;
	}

	@Override
    public Map<Object, Object> queryLemonShopList() {
        Map<Object, Object> map = new HashMap<Object, Object>();
        List<LemonShop> lemonshop_list = operativeMapper.queryLemonShopList();
        map.put("lemonshop_list", lemonshop_list);
        return map;
    }

    @Override
    public com.heatup.apt.model.Resource toPeratingEditBanner(Integer id) {
        return resourceMapper.selectByPrimaryKey(id);
    }

    
	@Override
	public List<CoachInf> queryCoachInfList() {
		return operativeMapper.queryCoachInfList();
	}

	
	
	@Override
	public void updateSortHomeFigure(String sortString) {
		
		sortString = sortString.replace("##undefined", "");
		List<String> sort_list = Arrays.asList(sortString.split("##"));
		for (int i=1;i<=sort_list.size();i++) {
			
			String string  = sort_list.get(i-1);
			
			if (StringUtil.isNotEmpty(string)) {
				
				if (string.contains("hf_")) {
					string = string.replace("hf_", "");
					
					String[] str = string.split("_");
					
					if (null != str && str.length == 2) {
						Map<Object, Object> params = new HashMap<Object, Object>();
						params.put("sortNum", i);
						params.put("id", str[0]);
						operativeMapper.updateSortResource(params);
					}
				}
			}
			
		}
		
	}

	@Override
	public void updateSortArticle(String sortString) {
		
		sortString = sortString.replace("##undefined", "");
		List<String> sort_list = Arrays.asList(sortString.split("##"));
		for (int i=1;i<=sort_list.size();i++) {
			
			String string  = sort_list.get(i-1);
			
			if (StringUtil.isNotEmpty(string)) {
				
				if (string.contains("hf_")) {
					string = string.replace("hf_", "");
					
					String[] str = string.split("_");
					
					if (null != str && str.length == 2) {
						Map<Object, Object> params = new HashMap<Object, Object>();
						params.put("sortNum", i);
						params.put("id", str[0]);
						operativeMapper.updateSortArticle(params);
					}
				}
			}
			
		}
	}
	
	/**
	 * 获取会员页轮播图
	 */
	@Override
	public Map<Object, Object> queryVipFirure() {
		 Map<Object, Object> map = new HashMap<Object, Object>();
		 List<VipFigure> homeFigures = operativeMapper.queryVipFigureList();
		 map.put("vipFigures", homeFigures);
		 return map;
	}
	
	/**
	 * 添加会员页中的轮播图
	 */
	@Override
	public int addVipbanner(MultipartFile multipartFile, HttpServletRequest request, String title, String previewUrl,
			SysUser user) throws Exception {
		com.heatup.apt.model.Resource resource = new com.heatup.apt.model.Resource();
        String path = request.getSession().getServletContext().getRealPath("img/vip/");
        String fileName = multipartFile.getOriginalFilename();
        System.out.println(path);
        File targetFile = new File(path, fileName);
        if(!targetFile.exists()){
            targetFile.mkdirs();
        }
        multipartFile.transferTo(targetFile);
        String actionUrl = OssFileUtil.uploadFile(path +"/"+ fileName, fileName);
        resource.setResType(ResourceResTypeEnum.image.getType());
        resource.setResKey("vip_banner");
        resource.setParentType("5");
        resource.setTitle(title);
        resource.setUrl(actionUrl);
        resource.setLink(previewUrl);
        resource.setCreatedBy(user.getId());
        resource.setCreatedTime(new Date());
        
        int count = resourceMapper.insertSelective(resource);
        
        resource.setSortNum(resource.getId());
        resourceMapper.updateByPrimaryKey(resource);
        return count;
	}
	
	/**
	 * 编辑会员页轮播图
	 */
	@Override
	public int editVipbanner(MultipartFile multipartFile, HttpServletRequest request, String title, String previewUrl,
			SysUser user) throws Exception {
		Integer id = Integer.valueOf(request.getParameter("resourceId"));
		com.heatup.apt.model.Resource resource = resourceMapper.selectByPrimaryKey(id);
		if(multipartFile != null && multipartFile.getSize() > 0L){
			String path = request.getSession().getServletContext().getRealPath("img/vip/");
	        String fileName = multipartFile.getOriginalFilename();
	        System.out.println(path);
	        File targetFile = new File(path, fileName);
	        if(!targetFile.exists()){
	            targetFile.mkdirs();
	        }
	        multipartFile.transferTo(targetFile);
	        String actionUrl = OssFileUtil.uploadFile(path +"/"+ fileName, fileName);
	        resource.setUrl(actionUrl);
		}
        
        resource.setResType(ResourceResTypeEnum.image.getType());
        resource.setResKey("vip_banner");
        resource.setParentType("5");
        resource.setTitle(title);
        resource.setLink(previewUrl);
        Integer count = resourceMapper.updateByPrimaryKey(resource);
        return count;
	}
	
	/**
	 * 会员页轮播图排序
	 */
	@Override
	public int updateSortVipbanner(String sortString) throws Exception {
		String [] vipBanner = sortString.split("#");
		Integer count = 0 ;
		for(int i=1;i<=vipBanner.length;i++){
			Map<Object, Object> params = new HashMap<Object, Object>();
			params.put("sortNum", i);
			params.put("id", vipBanner[i-1]);
			int counts = operativeMapper.updateSortResource(params);
			count++;
		}
		return count;
	}
	
	/**
	 * 获取会员页活动链接和内容
	 */
	@Override
	public Map<Object, Object> queryVipActivity() {
		Map<Object, Object> map = new HashMap<>();
		List<VipActivity> list = operativeMapper.queryVipActivityList();
		map.put("vipActivitys", list);
		return map;
	}
	
	/**
	 * 保存会员活动
	 * 
	 */
	@Override
	public int saveVipActivity(MultipartFile multipartFile, HttpServletRequest request, String title, String previewUrl,
			SysUser user) throws Exception {
		Integer id = Integer.valueOf(request.getParameter("resourceId"));
		if(id > 0){
			com.heatup.apt.model.Resource resource = resourceMapper.selectByPrimaryKey(id);
	        resource.setResType(ResourceResTypeEnum.image.getType());
	        resource.setResKey("vip_activity");
	        resource.setParentType("5");
	        resource.setTitle(title);
	        resource.setLink(previewUrl);
	        Integer count = resourceMapper.updateByPrimaryKey(resource);
	        return count;
		}else{
			com.heatup.apt.model.Resource resource = new com.heatup.apt.model.Resource();
	        resource.setResType(ResourceResTypeEnum.image.getType());
	        resource.setResKey("vip_activity");
	        resource.setParentType("5");
	        resource.setTitle(title);
	        resource.setLink(previewUrl);
	        Integer count = resourceMapper.insertSelective(resource);
	        return count;
		}
		
	}

	
	
}
